{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "107d19e7",
   "metadata": {},
   "source": [
    "---------------\n",
    "\n",
    "*本学习记录人：罗林胜   \n",
    "*学习时间：2021-12-2    \n",
    "*week09  \n",
    "*[参考的文档](https://www.python.org/doc/)  \n",
    "*[许老师博客](https://www.cnblogs.com/xuzhichao)  \n",
    "\n",
    "----------------\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "673ada81",
   "metadata": {},
   "source": [
    "## 本周知识点\n",
    "\n",
    "### 1.初始字典\n",
    "\n",
    "### 2.字典的一般创建方法\n",
    "\n",
    "### 3.字典的操作\n",
    "\n",
    "### 4.实践"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "445ce367",
   "metadata": {},
   "source": [
    "# 1. [初识字典](https://docs.python.org/3/tutorial/datastructures.html#dictionaries)\n",
    "\n",
    "* Another useful data type built into Python is the dictionary (see Mapping Types — dict) **映射数据类型**  \n",
    "* 对比序列数据 VS 映射数据  \n",
    ">\n",
    ">> 1.序列数据 index 是 从0开始，每次加一的 数值作为索引值 [88,87,90]  {0:88 , 1:87, 2:90}  \n",
    ">> 2.映射数据 index 是 **关键字**（不可变数据，例如字符串，数字，元组）  \n",
    ">> 3.序列数据是 **有顺序的**  \n",
    ">> 4.映射数据是 **无序的**(哈希算法)  \n",
    ">> 5.序列数据 index 是不写在数据值中的，不显示的  \n",
    ">> 6.映射数据 index 作为 关键字（key）写在数据结构中 ： {key:value} 这种形式通常被人们称为 **键值对**（key: value pairs） \n",
    ">\n",
    "\n",
    "*总结字典的性质：\n",
    "> 1.字典的key 是唯一的 (唯一性)  \n",
    "> 2.字典是没有顺序的（无序性）  \n",
    "> 3.字典的key是不可变的(不变性)  \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "4c76e5f3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'dict'>\n",
      "{'linseng': 4098, 'ziqi': 4139}\n"
     ]
    }
   ],
   "source": [
    "tel={'linseng':4098,'ziqi':4139}\n",
    "print(type(tel))\n",
    "print(tel)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b2064a9f",
   "metadata": {},
   "source": [
    "> 'linsheng'是关键字(key)  \n",
    "> '4098'是值(value)  "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "282adcd5",
   "metadata": {},
   "source": [
    "## 2.字典的一般创建方法\n",
    "\n",
    "> 1.按照字典的数据结构直接创建  \n",
    ">> * dict_name = {key1:value1 , key2:value2 , key3:value3 , ...}  \n",
    ">\n",
    "> 2.使用dict()方法创建字典  \n",
    ">> * dict_name = dict(key1=value1 , key2=value2 , key3=value3 , ...)  \n",
    ">\n",
    "> 3.使用字典新增的方式创建字典  \n",
    ">> * dict_name[key1] = value1 , dict_name[key2] = value2 , dict_name[key3] = value3 ,...  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "8bca514d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'stud_2101': 'luolinsheng', 'stud_2102': 'luolinsheng', 'stud_2103': 'xiaojun'}\n"
     ]
    }
   ],
   "source": [
    "# 1. 按照字典的形式创建字典\n",
    "stud_info={\n",
    "    \"stud_2101\":\"luolinsheng\",\n",
    "    \"stud_2102\":\"luolinsheng\",\n",
    "    \"stud_2103\":\"xiaojun\"\n",
    "}\n",
    "print(stud_info)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "935f53bb",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'stud_2101': 'luolinsheng', 'stud_2102': 'luolinsheng', 'stud_2103': 'xiaojun'}\n"
     ]
    }
   ],
   "source": [
    "# 2.使用dict()方法创建字典\n",
    "stud_info2=dict(\n",
    "    stud_2101=\"luolinsheng\",\n",
    "    stud_2102=\"luolinsheng\",\n",
    "    stud_2103=\"xiaojun\"\n",
    ")\n",
    "print(stud_info2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "5586ed5b",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'stud_2101': 'luolinsheng', 'stud_2102': 'luolinsheng', 'stud_2103': 'xiaojun'}\n"
     ]
    }
   ],
   "source": [
    "# 3.使用字典新增的方式创建字典\n",
    "stud_info3={}\n",
    "\n",
    "stud_info3[\"stud_2101\"]=\"luolinsheng\"\n",
    "stud_info3[\"stud_2102\"]=\"luolinsheng\"\n",
    "stud_info3[\"stud_2103\"]=\"xiaojun\"\n",
    "\n",
    "print(stud_info3)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a504d5ae",
   "metadata": {},
   "source": [
    "## 3.字典的操作\n",
    "\n",
    "\n",
    "> 1.字典的增删改<font style='color:red'>**查**  \n",
    "    \n",
    ">> 1.字典的查询(按照关键字（key）进行查询)\n",
    "    \n",
    "> 2.字典的一般方法 \n",
    "\n",
    "> 1.字典的查询    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "d52fd9b2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'stud_2101': 'luolinsheng',\n",
       " 'stud_2102': 'luolinsheng',\n",
       " 'stud_2103': 'xiaojun'}"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stud_info"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "6cb16e75",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "luolinsheng\n"
     ]
    }
   ],
   "source": [
    "# 字典的查询方法\n",
    "if 'stud_2102' in stud_info:\n",
    "    print(stud_info['stud_2102'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "37970e48",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'stud_2104' in stud_info"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "86226c37",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "luolinsheng\n"
     ]
    }
   ],
   "source": [
    "# 字典的查询方法2：\n",
    "# 利用dict.get()查询，如果值存在的话，直接返回查询方法；如果值不存在，返回none\n",
    "print(stud_info.get('stud_2102'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "af46bc0c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "None\n"
     ]
    }
   ],
   "source": [
    "print(stud_info.get('stud_2104'))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a883076f",
   "metadata": {},
   "source": [
    "> 2.字典的修改和增加：dict[key]=value\n",
    ">> 1.查询是否存在，如果存在的话，修改  \n",
    ">> 1.查询是否存在，如果不存在的话，增加"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "afa9a351",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'stud_2101': 'luolinsheng',\n",
       " 'stud_2102': 'luolinsheng',\n",
       " 'stud_2103': 'xiaojun'}"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stud_info"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "41bf2d85",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 1. 字典的增加\n",
    "'stud_2104' in stud_info"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "b86aed26",
   "metadata": {},
   "outputs": [],
   "source": [
    "stud_info['stud_2104']='xiaoyu'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "17c3bb29",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'stud_2101': 'luolinsheng',\n",
       " 'stud_2102': 'luolinsheng',\n",
       " 'stud_2103': 'xiaojun',\n",
       " 'stud_2104': 'xiaoyu'}"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stud_info"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "6f2b02b7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 字典的修改\n",
    "'stud_2102' in stud_info"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "ed404226",
   "metadata": {},
   "outputs": [],
   "source": [
    "stud_info['stud_2102']='jack'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "c12f5059",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'stud_2101': 'luolinsheng',\n",
       " 'stud_2102': 'jack',\n",
       " 'stud_2103': 'xiaojun',\n",
       " 'stud_2104': 'xiaoyu'}"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stud_info"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a26ea870",
   "metadata": {},
   "source": [
    "> 3.字典的删除\n",
    ">> 1.pop()指定关键字进行删除  \n",
    ">> 2.popitem()随机删除一个字典的内容，返回删除的键对信息  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "1d240d55",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function pop:\n",
      "\n",
      "pop(...) method of builtins.dict instance\n",
      "    D.pop(k[,d]) -> v, remove specified key and return the corresponding value.\n",
      "    If key is not found, d is returned if given, otherwise KeyError is raised\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(stud_info.pop)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "628164cb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'stud_2102'in stud_info"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "61a0751f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'jack'"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stud_info.pop('stud_2102')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "4cd23593",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'stud_2101': 'luolinsheng', 'stud_2103': 'xiaojun', 'stud_2104': 'xiaoyu'}"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stud_info"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "3c8c3d79",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function popitem:\n",
      "\n",
      "popitem() method of builtins.dict instance\n",
      "    Remove and return a (key, value) pair as a 2-tuple.\n",
      "    \n",
      "    Pairs are returned in LIFO (last-in, first-out) order.\n",
      "    Raises KeyError if the dict is empty.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(stud_info.popitem)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "5b359b2f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "('stud_2104', 'xiaoyu')"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stud_info.popitem()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "cc7c9f40",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'stud_2101': 'luolinsheng', 'stud_2103': 'xiaojun'}"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stud_info"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d9611554",
   "metadata": {},
   "source": [
    "> 4.字典的循环\n",
    ">> 1.根据字典的key；value的结构，我们循环将循环**两个变量**  \n",
    ">> 2.方法for k,v in Dict.items()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "b3736ba6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'stud_2101': 'luolinsheng',\n",
       " 'stud_2102': 'luolinsheng',\n",
       " 'stud_2103': 'xiaojun'}"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stud_info2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "1ad21fdb",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "stud_2101 luolinsheng\n",
      "stud_2102 luolinsheng\n",
      "stud_2103 xiaojun\n"
     ]
    }
   ],
   "source": [
    "for k,v in stud_info2.items():\n",
    "    print(k,v)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f0222742",
   "metadata": {},
   "source": [
    "# 4.字典的一般方法（课后实践） \n",
    "\n",
    "> 1.使用help()查看**每一种**字典的方法  \n",
    "> 2.如果没看懂，请搜索浏览器找寻答案  \n",
    "> 3.实践每一种方法  \n",
    "> 4. 使用表格总结每一种方法"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d507f18c",
   "metadata": {},
   "source": [
    "# 字典的查询实践\n",
    "\n",
    "> 1.请大家找出来，关键字为industryCondition 的数据：dict[key]  \n",
    "> 2.请大家找出来 'code' 为 020 的所有数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "882deb95",
   "metadata": {},
   "outputs": [],
   "source": [
    "test_dict = {\"flag\":1,\"data\":{\"educationCondition\":[{\"code\":\"010\",\"name\":\"博士\"},{\"code\":\"020\",\"name\":\"MBA/EMBA\"},{\"code\":\"030\",\"name\":\"硕士\"},{\"code\":\"040\",\"name\":\"本科\"},{\"code\":\"050\",\"name\":\"大专\"},{\"code\":\"060\",\"name\":\"中专/中技\"},{\"code\":\"080\",\"name\":\"高中\"},{\"code\":\"090\",\"name\":\"初中及以下\"}],\"jobKindCondition\":[{\"code\":\"1\",\"name\":\"猎头职位\"},{\"code\":\"2\",\"name\":\"企业职位\"}],\"stageCondition\":[{\"code\":\"01\",\"name\":\"天使轮\"},{\"code\":\"02\",\"name\":\"A轮\"},{\"code\":\"03\",\"name\":\"B轮\"},{\"code\":\"04\",\"name\":\"C轮\"},{\"code\":\"05\",\"name\":\"D轮及以上\"},{\"code\":\"06\",\"name\":\"已上市\"},{\"code\":\"07\",\"name\":\"战略融资\"},{\"code\":\"08\",\"name\":\"融资未公开\"},{\"code\":\"99\",\"name\":\"其他\"}],\"scaleCondition\":[{\"code\":\"010\",\"name\":\"1-49人\"},{\"code\":\"020\",\"name\":\"50-99人\"},{\"code\":\"030\",\"name\":\"100-499人\"},{\"code\":\"040\",\"name\":\"500-999人\"},{\"code\":\"050\",\"name\":\"1000-2000人\"},{\"code\":\"060\",\"name\":\"2000-5000人\"},{\"code\":\"070\",\"name\":\"5000-10000人\"},{\"code\":\"080\",\"name\":\"10000人以上\"}],\"compKindCondition\":[{\"code\":\"010\",\"name\":\"外商独资·外企办事处\"},{\"code\":\"020\",\"name\":\"中外合营(合资·合作)\"},{\"code\":\"030\",\"name\":\"私营·民营企业\"},{\"code\":\"040\",\"name\":\"国有企业\"},{\"code\":\"050\",\"name\":\"国内上市公司\"},{\"code\":\"060\",\"name\":\"政府机关／非盈利机构\"},{\"code\":\"070\",\"name\":\"事业单位\"},{\"code\":\"999\",\"name\":\"其他\"}],\"industryCondition\":[{\"code\":\"1\",\"children\":[{\"code\":\"040\",\"name\":\"互联网/移动互联网/电子商务\"},{\"code\":\"420\",\"name\":\"游戏产业\"},{\"code\":\"010\",\"name\":\"计算机软件\"},{\"code\":\"030\",\"name\":\"IT服务/系统集成\"}],\"name\":\"互联网.游戏.软件\"},{\"code\":\"2\",\"children\":[{\"code\":\"050\",\"name\":\"电子技术/半导体/集成电路\"},{\"code\":\"060\",\"name\":\"通信(设备/运营/增值)\"},{\"code\":\"020\",\"name\":\"计算机硬件/网络设备\"}],\"name\":\"电子.通信.硬件\"},{\"code\":\"3\",\"children\":[{\"code\":\"080\",\"name\":\"房地产开发/建筑/建材/工程\"},{\"code\":\"090\",\"name\":\"房地产服务(物业管理/地产经纪)\"},{\"code\":\"100\",\"name\":\"规划/设计/装潢\"}],\"name\":\"房地产.建筑.物业\"},{\"code\":\"4\",\"children\":[{\"code\":\"130\",\"name\":\"银行\"},{\"code\":\"140\",\"name\":\"保险\"},{\"code\":\"150\",\"name\":\"基金/证券/期货/投资\"},{\"code\":\"430\",\"name\":\"会计/审计\"},{\"code\":\"500\",\"name\":\"信托/担保/拍卖/典当\"}],\"name\":\"金融\"},{\"code\":\"5\",\"children\":[{\"code\":\"190\",\"name\":\"食品/饮料/烟酒/日化\"},{\"code\":\"240\",\"name\":\"百货/批发/零售\"},{\"code\":\"200\",\"name\":\"服装服饰/纺织/皮革\"},{\"code\":\"210\",\"name\":\"家具/家电\"},{\"code\":\"220\",\"name\":\"办公用品及设备\"},{\"code\":\"460\",\"name\":\"奢侈品/收藏品\"},{\"code\":\"470\",\"name\":\"工艺品/珠宝/玩具\"}],\"name\":\"消费品\"},{\"code\":\"6\",\"children\":[{\"code\":\"350\",\"name\":\"汽车/摩托车\"},{\"code\":\"360\",\"name\":\"机械制造/机电/重工\"},{\"code\":\"180\",\"name\":\"印刷/包装/造纸\"},{\"code\":\"340\",\"name\":\"仪器/仪表/工业自动化/电气\"},{\"code\":\"370\",\"name\":\"原材料及加工\"}],\"name\":\"汽车.机械.制造\"},{\"code\":\"7\",\"children\":[{\"code\":\"110\",\"name\":\"中介服务\"},{\"code\":\"120\",\"name\":\"专业服务(咨询/财会/法律/翻译等)\"},{\"code\":\"440\",\"name\":\"外包服务\"},{\"code\":\"450\",\"name\":\"检测/认证\"},{\"code\":\"230\",\"name\":\"旅游/酒店/餐饮服务/生活服务\"},{\"code\":\"260\",\"name\":\"娱乐/休闲/体育\"},{\"code\":\"510\",\"name\":\"租赁服务\"}],\"name\":\"服务.外包.中介\"},{\"code\":\"8\",\"children\":[{\"code\":\"070\",\"name\":\"广告/公关/市场推广/会展\"},{\"code\":\"170\",\"name\":\"影视/媒体/艺术/文化/出版\"},{\"code\":\"380\",\"name\":\"教育/培训/学术/科研/院校\"}],\"name\":\"广告.传媒.教育.文化\"},{\"code\":\"9\",\"children\":[{\"code\":\"250\",\"name\":\"交通/物流/运输\"},{\"code\":\"160\",\"name\":\"贸易/进出口\"},{\"code\":\"480\",\"name\":\"航空/航天\"}],\"name\":\"交通.贸易.物流\"},{\"code\":\"10\",\"children\":[{\"code\":\"270\",\"name\":\"制药/生物工程\"},{\"code\":\"280\",\"name\":\"医疗/保健/美容/卫生服务\"},{\"code\":\"290\",\"name\":\"医疗设备/器械\"}],\"name\":\"制药.医疗\"},{\"code\":\"11\",\"children\":[{\"code\":\"300\",\"name\":\"环保\"},{\"code\":\"310\",\"name\":\"石油/石化/化工\"},{\"code\":\"320\",\"name\":\"采掘/冶炼/矿产\"},{\"code\":\"330\",\"name\":\"能源(电力/水利)\"},{\"code\":\"490\",\"name\":\"新能源\"}],\"name\":\"能源.化工.环保\"},{\"code\":\"12\",\"children\":[{\"code\":\"390\",\"name\":\"政府/公共事业/非营利机构\"},{\"code\":\"410\",\"name\":\"农/林/牧/渔\"},{\"code\":\"400\",\"name\":\"其他\"}],\"name\":\"政府.农林牧渔\"}]}}\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "e9a7b6cd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'flag': 1,\n",
       " 'data': {'educationCondition': [{'code': '010', 'name': '博士'},\n",
       "   {'code': '020', 'name': 'MBA/EMBA'},\n",
       "   {'code': '030', 'name': '硕士'},\n",
       "   {'code': '040', 'name': '本科'},\n",
       "   {'code': '050', 'name': '大专'},\n",
       "   {'code': '060', 'name': '中专/中技'},\n",
       "   {'code': '080', 'name': '高中'},\n",
       "   {'code': '090', 'name': '初中及以下'}],\n",
       "  'jobKindCondition': [{'code': '1', 'name': '猎头职位'},\n",
       "   {'code': '2', 'name': '企业职位'}],\n",
       "  'stageCondition': [{'code': '01', 'name': '天使轮'},\n",
       "   {'code': '02', 'name': 'A轮'},\n",
       "   {'code': '03', 'name': 'B轮'},\n",
       "   {'code': '04', 'name': 'C轮'},\n",
       "   {'code': '05', 'name': 'D轮及以上'},\n",
       "   {'code': '06', 'name': '已上市'},\n",
       "   {'code': '07', 'name': '战略融资'},\n",
       "   {'code': '08', 'name': '融资未公开'},\n",
       "   {'code': '99', 'name': '其他'}],\n",
       "  'scaleCondition': [{'code': '010', 'name': '1-49人'},\n",
       "   {'code': '020', 'name': '50-99人'},\n",
       "   {'code': '030', 'name': '100-499人'},\n",
       "   {'code': '040', 'name': '500-999人'},\n",
       "   {'code': '050', 'name': '1000-2000人'},\n",
       "   {'code': '060', 'name': '2000-5000人'},\n",
       "   {'code': '070', 'name': '5000-10000人'},\n",
       "   {'code': '080', 'name': '10000人以上'}],\n",
       "  'compKindCondition': [{'code': '010', 'name': '外商独资·外企办事处'},\n",
       "   {'code': '020', 'name': '中外合营(合资·合作)'},\n",
       "   {'code': '030', 'name': '私营·民营企业'},\n",
       "   {'code': '040', 'name': '国有企业'},\n",
       "   {'code': '050', 'name': '国内上市公司'},\n",
       "   {'code': '060', 'name': '政府机关／非盈利机构'},\n",
       "   {'code': '070', 'name': '事业单位'},\n",
       "   {'code': '999', 'name': '其他'}],\n",
       "  'industryCondition': [{'code': '1',\n",
       "    'children': [{'code': '040', 'name': '互联网/移动互联网/电子商务'},\n",
       "     {'code': '420', 'name': '游戏产业'},\n",
       "     {'code': '010', 'name': '计算机软件'},\n",
       "     {'code': '030', 'name': 'IT服务/系统集成'}],\n",
       "    'name': '互联网.游戏.软件'},\n",
       "   {'code': '2',\n",
       "    'children': [{'code': '050', 'name': '电子技术/半导体/集成电路'},\n",
       "     {'code': '060', 'name': '通信(设备/运营/增值)'},\n",
       "     {'code': '020', 'name': '计算机硬件/网络设备'}],\n",
       "    'name': '电子.通信.硬件'},\n",
       "   {'code': '3',\n",
       "    'children': [{'code': '080', 'name': '房地产开发/建筑/建材/工程'},\n",
       "     {'code': '090', 'name': '房地产服务(物业管理/地产经纪)'},\n",
       "     {'code': '100', 'name': '规划/设计/装潢'}],\n",
       "    'name': '房地产.建筑.物业'},\n",
       "   {'code': '4',\n",
       "    'children': [{'code': '130', 'name': '银行'},\n",
       "     {'code': '140', 'name': '保险'},\n",
       "     {'code': '150', 'name': '基金/证券/期货/投资'},\n",
       "     {'code': '430', 'name': '会计/审计'},\n",
       "     {'code': '500', 'name': '信托/担保/拍卖/典当'}],\n",
       "    'name': '金融'},\n",
       "   {'code': '5',\n",
       "    'children': [{'code': '190', 'name': '食品/饮料/烟酒/日化'},\n",
       "     {'code': '240', 'name': '百货/批发/零售'},\n",
       "     {'code': '200', 'name': '服装服饰/纺织/皮革'},\n",
       "     {'code': '210', 'name': '家具/家电'},\n",
       "     {'code': '220', 'name': '办公用品及设备'},\n",
       "     {'code': '460', 'name': '奢侈品/收藏品'},\n",
       "     {'code': '470', 'name': '工艺品/珠宝/玩具'}],\n",
       "    'name': '消费品'},\n",
       "   {'code': '6',\n",
       "    'children': [{'code': '350', 'name': '汽车/摩托车'},\n",
       "     {'code': '360', 'name': '机械制造/机电/重工'},\n",
       "     {'code': '180', 'name': '印刷/包装/造纸'},\n",
       "     {'code': '340', 'name': '仪器/仪表/工业自动化/电气'},\n",
       "     {'code': '370', 'name': '原材料及加工'}],\n",
       "    'name': '汽车.机械.制造'},\n",
       "   {'code': '7',\n",
       "    'children': [{'code': '110', 'name': '中介服务'},\n",
       "     {'code': '120', 'name': '专业服务(咨询/财会/法律/翻译等)'},\n",
       "     {'code': '440', 'name': '外包服务'},\n",
       "     {'code': '450', 'name': '检测/认证'},\n",
       "     {'code': '230', 'name': '旅游/酒店/餐饮服务/生活服务'},\n",
       "     {'code': '260', 'name': '娱乐/休闲/体育'},\n",
       "     {'code': '510', 'name': '租赁服务'}],\n",
       "    'name': '服务.外包.中介'},\n",
       "   {'code': '8',\n",
       "    'children': [{'code': '070', 'name': '广告/公关/市场推广/会展'},\n",
       "     {'code': '170', 'name': '影视/媒体/艺术/文化/出版'},\n",
       "     {'code': '380', 'name': '教育/培训/学术/科研/院校'}],\n",
       "    'name': '广告.传媒.教育.文化'},\n",
       "   {'code': '9',\n",
       "    'children': [{'code': '250', 'name': '交通/物流/运输'},\n",
       "     {'code': '160', 'name': '贸易/进出口'},\n",
       "     {'code': '480', 'name': '航空/航天'}],\n",
       "    'name': '交通.贸易.物流'},\n",
       "   {'code': '10',\n",
       "    'children': [{'code': '270', 'name': '制药/生物工程'},\n",
       "     {'code': '280', 'name': '医疗/保健/美容/卫生服务'},\n",
       "     {'code': '290', 'name': '医疗设备/器械'}],\n",
       "    'name': '制药.医疗'},\n",
       "   {'code': '11',\n",
       "    'children': [{'code': '300', 'name': '环保'},\n",
       "     {'code': '310', 'name': '石油/石化/化工'},\n",
       "     {'code': '320', 'name': '采掘/冶炼/矿产'},\n",
       "     {'code': '330', 'name': '能源(电力/水利)'},\n",
       "     {'code': '490', 'name': '新能源'}],\n",
       "    'name': '能源.化工.环保'},\n",
       "   {'code': '12',\n",
       "    'children': [{'code': '390', 'name': '政府/公共事业/非营利机构'},\n",
       "     {'code': '410', 'name': '农/林/牧/渔'},\n",
       "     {'code': '400', 'name': '其他'}],\n",
       "    'name': '政府.农林牧渔'}]}}"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "test_dict"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "58ebf29b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "dict_keys(['flag', 'data'])"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "test_dict.keys()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "9891f102",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "test_dict['flag']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "d3520468",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'educationCondition': [{'code': '010', 'name': '博士'},\n",
       "  {'code': '020', 'name': 'MBA/EMBA'},\n",
       "  {'code': '030', 'name': '硕士'},\n",
       "  {'code': '040', 'name': '本科'},\n",
       "  {'code': '050', 'name': '大专'},\n",
       "  {'code': '060', 'name': '中专/中技'},\n",
       "  {'code': '080', 'name': '高中'},\n",
       "  {'code': '090', 'name': '初中及以下'}],\n",
       " 'jobKindCondition': [{'code': '1', 'name': '猎头职位'},\n",
       "  {'code': '2', 'name': '企业职位'}],\n",
       " 'stageCondition': [{'code': '01', 'name': '天使轮'},\n",
       "  {'code': '02', 'name': 'A轮'},\n",
       "  {'code': '03', 'name': 'B轮'},\n",
       "  {'code': '04', 'name': 'C轮'},\n",
       "  {'code': '05', 'name': 'D轮及以上'},\n",
       "  {'code': '06', 'name': '已上市'},\n",
       "  {'code': '07', 'name': '战略融资'},\n",
       "  {'code': '08', 'name': '融资未公开'},\n",
       "  {'code': '99', 'name': '其他'}],\n",
       " 'scaleCondition': [{'code': '010', 'name': '1-49人'},\n",
       "  {'code': '020', 'name': '50-99人'},\n",
       "  {'code': '030', 'name': '100-499人'},\n",
       "  {'code': '040', 'name': '500-999人'},\n",
       "  {'code': '050', 'name': '1000-2000人'},\n",
       "  {'code': '060', 'name': '2000-5000人'},\n",
       "  {'code': '070', 'name': '5000-10000人'},\n",
       "  {'code': '080', 'name': '10000人以上'}],\n",
       " 'compKindCondition': [{'code': '010', 'name': '外商独资·外企办事处'},\n",
       "  {'code': '020', 'name': '中外合营(合资·合作)'},\n",
       "  {'code': '030', 'name': '私营·民营企业'},\n",
       "  {'code': '040', 'name': '国有企业'},\n",
       "  {'code': '050', 'name': '国内上市公司'},\n",
       "  {'code': '060', 'name': '政府机关／非盈利机构'},\n",
       "  {'code': '070', 'name': '事业单位'},\n",
       "  {'code': '999', 'name': '其他'}],\n",
       " 'industryCondition': [{'code': '1',\n",
       "   'children': [{'code': '040', 'name': '互联网/移动互联网/电子商务'},\n",
       "    {'code': '420', 'name': '游戏产业'},\n",
       "    {'code': '010', 'name': '计算机软件'},\n",
       "    {'code': '030', 'name': 'IT服务/系统集成'}],\n",
       "   'name': '互联网.游戏.软件'},\n",
       "  {'code': '2',\n",
       "   'children': [{'code': '050', 'name': '电子技术/半导体/集成电路'},\n",
       "    {'code': '060', 'name': '通信(设备/运营/增值)'},\n",
       "    {'code': '020', 'name': '计算机硬件/网络设备'}],\n",
       "   'name': '电子.通信.硬件'},\n",
       "  {'code': '3',\n",
       "   'children': [{'code': '080', 'name': '房地产开发/建筑/建材/工程'},\n",
       "    {'code': '090', 'name': '房地产服务(物业管理/地产经纪)'},\n",
       "    {'code': '100', 'name': '规划/设计/装潢'}],\n",
       "   'name': '房地产.建筑.物业'},\n",
       "  {'code': '4',\n",
       "   'children': [{'code': '130', 'name': '银行'},\n",
       "    {'code': '140', 'name': '保险'},\n",
       "    {'code': '150', 'name': '基金/证券/期货/投资'},\n",
       "    {'code': '430', 'name': '会计/审计'},\n",
       "    {'code': '500', 'name': '信托/担保/拍卖/典当'}],\n",
       "   'name': '金融'},\n",
       "  {'code': '5',\n",
       "   'children': [{'code': '190', 'name': '食品/饮料/烟酒/日化'},\n",
       "    {'code': '240', 'name': '百货/批发/零售'},\n",
       "    {'code': '200', 'name': '服装服饰/纺织/皮革'},\n",
       "    {'code': '210', 'name': '家具/家电'},\n",
       "    {'code': '220', 'name': '办公用品及设备'},\n",
       "    {'code': '460', 'name': '奢侈品/收藏品'},\n",
       "    {'code': '470', 'name': '工艺品/珠宝/玩具'}],\n",
       "   'name': '消费品'},\n",
       "  {'code': '6',\n",
       "   'children': [{'code': '350', 'name': '汽车/摩托车'},\n",
       "    {'code': '360', 'name': '机械制造/机电/重工'},\n",
       "    {'code': '180', 'name': '印刷/包装/造纸'},\n",
       "    {'code': '340', 'name': '仪器/仪表/工业自动化/电气'},\n",
       "    {'code': '370', 'name': '原材料及加工'}],\n",
       "   'name': '汽车.机械.制造'},\n",
       "  {'code': '7',\n",
       "   'children': [{'code': '110', 'name': '中介服务'},\n",
       "    {'code': '120', 'name': '专业服务(咨询/财会/法律/翻译等)'},\n",
       "    {'code': '440', 'name': '外包服务'},\n",
       "    {'code': '450', 'name': '检测/认证'},\n",
       "    {'code': '230', 'name': '旅游/酒店/餐饮服务/生活服务'},\n",
       "    {'code': '260', 'name': '娱乐/休闲/体育'},\n",
       "    {'code': '510', 'name': '租赁服务'}],\n",
       "   'name': '服务.外包.中介'},\n",
       "  {'code': '8',\n",
       "   'children': [{'code': '070', 'name': '广告/公关/市场推广/会展'},\n",
       "    {'code': '170', 'name': '影视/媒体/艺术/文化/出版'},\n",
       "    {'code': '380', 'name': '教育/培训/学术/科研/院校'}],\n",
       "   'name': '广告.传媒.教育.文化'},\n",
       "  {'code': '9',\n",
       "   'children': [{'code': '250', 'name': '交通/物流/运输'},\n",
       "    {'code': '160', 'name': '贸易/进出口'},\n",
       "    {'code': '480', 'name': '航空/航天'}],\n",
       "   'name': '交通.贸易.物流'},\n",
       "  {'code': '10',\n",
       "   'children': [{'code': '270', 'name': '制药/生物工程'},\n",
       "    {'code': '280', 'name': '医疗/保健/美容/卫生服务'},\n",
       "    {'code': '290', 'name': '医疗设备/器械'}],\n",
       "   'name': '制药.医疗'},\n",
       "  {'code': '11',\n",
       "   'children': [{'code': '300', 'name': '环保'},\n",
       "    {'code': '310', 'name': '石油/石化/化工'},\n",
       "    {'code': '320', 'name': '采掘/冶炼/矿产'},\n",
       "    {'code': '330', 'name': '能源(电力/水利)'},\n",
       "    {'code': '490', 'name': '新能源'}],\n",
       "   'name': '能源.化工.环保'},\n",
       "  {'code': '12',\n",
       "   'children': [{'code': '390', 'name': '政府/公共事业/非营利机构'},\n",
       "    {'code': '410', 'name': '农/林/牧/渔'},\n",
       "    {'code': '400', 'name': '其他'}],\n",
       "   'name': '政府.农林牧渔'}]}"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "test_dict['data']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "728867d7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "dict_keys(['educationCondition', 'jobKindCondition', 'stageCondition', 'scaleCondition', 'compKindCondition', 'industryCondition'])"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "test_dict['data'].keys()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "5e07ff11",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{'code': '1',\n",
       "  'children': [{'code': '040', 'name': '互联网/移动互联网/电子商务'},\n",
       "   {'code': '420', 'name': '游戏产业'},\n",
       "   {'code': '010', 'name': '计算机软件'},\n",
       "   {'code': '030', 'name': 'IT服务/系统集成'}],\n",
       "  'name': '互联网.游戏.软件'},\n",
       " {'code': '2',\n",
       "  'children': [{'code': '050', 'name': '电子技术/半导体/集成电路'},\n",
       "   {'code': '060', 'name': '通信(设备/运营/增值)'},\n",
       "   {'code': '020', 'name': '计算机硬件/网络设备'}],\n",
       "  'name': '电子.通信.硬件'},\n",
       " {'code': '3',\n",
       "  'children': [{'code': '080', 'name': '房地产开发/建筑/建材/工程'},\n",
       "   {'code': '090', 'name': '房地产服务(物业管理/地产经纪)'},\n",
       "   {'code': '100', 'name': '规划/设计/装潢'}],\n",
       "  'name': '房地产.建筑.物业'},\n",
       " {'code': '4',\n",
       "  'children': [{'code': '130', 'name': '银行'},\n",
       "   {'code': '140', 'name': '保险'},\n",
       "   {'code': '150', 'name': '基金/证券/期货/投资'},\n",
       "   {'code': '430', 'name': '会计/审计'},\n",
       "   {'code': '500', 'name': '信托/担保/拍卖/典当'}],\n",
       "  'name': '金融'},\n",
       " {'code': '5',\n",
       "  'children': [{'code': '190', 'name': '食品/饮料/烟酒/日化'},\n",
       "   {'code': '240', 'name': '百货/批发/零售'},\n",
       "   {'code': '200', 'name': '服装服饰/纺织/皮革'},\n",
       "   {'code': '210', 'name': '家具/家电'},\n",
       "   {'code': '220', 'name': '办公用品及设备'},\n",
       "   {'code': '460', 'name': '奢侈品/收藏品'},\n",
       "   {'code': '470', 'name': '工艺品/珠宝/玩具'}],\n",
       "  'name': '消费品'},\n",
       " {'code': '6',\n",
       "  'children': [{'code': '350', 'name': '汽车/摩托车'},\n",
       "   {'code': '360', 'name': '机械制造/机电/重工'},\n",
       "   {'code': '180', 'name': '印刷/包装/造纸'},\n",
       "   {'code': '340', 'name': '仪器/仪表/工业自动化/电气'},\n",
       "   {'code': '370', 'name': '原材料及加工'}],\n",
       "  'name': '汽车.机械.制造'},\n",
       " {'code': '7',\n",
       "  'children': [{'code': '110', 'name': '中介服务'},\n",
       "   {'code': '120', 'name': '专业服务(咨询/财会/法律/翻译等)'},\n",
       "   {'code': '440', 'name': '外包服务'},\n",
       "   {'code': '450', 'name': '检测/认证'},\n",
       "   {'code': '230', 'name': '旅游/酒店/餐饮服务/生活服务'},\n",
       "   {'code': '260', 'name': '娱乐/休闲/体育'},\n",
       "   {'code': '510', 'name': '租赁服务'}],\n",
       "  'name': '服务.外包.中介'},\n",
       " {'code': '8',\n",
       "  'children': [{'code': '070', 'name': '广告/公关/市场推广/会展'},\n",
       "   {'code': '170', 'name': '影视/媒体/艺术/文化/出版'},\n",
       "   {'code': '380', 'name': '教育/培训/学术/科研/院校'}],\n",
       "  'name': '广告.传媒.教育.文化'},\n",
       " {'code': '9',\n",
       "  'children': [{'code': '250', 'name': '交通/物流/运输'},\n",
       "   {'code': '160', 'name': '贸易/进出口'},\n",
       "   {'code': '480', 'name': '航空/航天'}],\n",
       "  'name': '交通.贸易.物流'},\n",
       " {'code': '10',\n",
       "  'children': [{'code': '270', 'name': '制药/生物工程'},\n",
       "   {'code': '280', 'name': '医疗/保健/美容/卫生服务'},\n",
       "   {'code': '290', 'name': '医疗设备/器械'}],\n",
       "  'name': '制药.医疗'},\n",
       " {'code': '11',\n",
       "  'children': [{'code': '300', 'name': '环保'},\n",
       "   {'code': '310', 'name': '石油/石化/化工'},\n",
       "   {'code': '320', 'name': '采掘/冶炼/矿产'},\n",
       "   {'code': '330', 'name': '能源(电力/水利)'},\n",
       "   {'code': '490', 'name': '新能源'}],\n",
       "  'name': '能源.化工.环保'},\n",
       " {'code': '12',\n",
       "  'children': [{'code': '390', 'name': '政府/公共事业/非营利机构'},\n",
       "   {'code': '410', 'name': '农/林/牧/渔'},\n",
       "   {'code': '400', 'name': '其他'}],\n",
       "  'name': '政府.农林牧渔'}]"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "test_dict['data']['industryCondition']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "cd1a814d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "12"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(test_dict['data']['industryCondition'])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "83861990",
   "metadata": {},
   "source": [
    "* 把行业信息 找出来存成一个列表"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a9eb0800",
   "metadata": {},
   "source": [
    "# 练习"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e8606d8e",
   "metadata": {},
   "source": [
    "###  1.查询字典的每种方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "505b3f13",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on class dict in module builtins:\n",
      "\n",
      "class dict(object)\n",
      " |  dict() -> new empty dictionary\n",
      " |  dict(mapping) -> new dictionary initialized from a mapping object's\n",
      " |      (key, value) pairs\n",
      " |  dict(iterable) -> new dictionary initialized as if via:\n",
      " |      d = {}\n",
      " |      for k, v in iterable:\n",
      " |          d[k] = v\n",
      " |  dict(**kwargs) -> new dictionary initialized with the name=value pairs\n",
      " |      in the keyword argument list.  For example:  dict(one=1, two=2)\n",
      " |  \n",
      " |  Built-in subclasses:\n",
      " |      StgDict\n",
      " |  \n",
      " |  Methods defined here:\n",
      " |  \n",
      " |  __contains__(self, key, /)\n",
      " |      True if the dictionary has the specified key, else False.\n",
      " |  \n",
      " |  __delitem__(self, key, /)\n",
      " |      Delete self[key].\n",
      " |  \n",
      " |  __eq__(self, value, /)\n",
      " |      Return self==value.\n",
      " |  \n",
      " |  __ge__(self, value, /)\n",
      " |      Return self>=value.\n",
      " |  \n",
      " |  __getattribute__(self, name, /)\n",
      " |      Return getattr(self, name).\n",
      " |  \n",
      " |  __getitem__(...)\n",
      " |      x.__getitem__(y) <==> x[y]\n",
      " |  \n",
      " |  __gt__(self, value, /)\n",
      " |      Return self>value.\n",
      " |  \n",
      " |  __init__(self, /, *args, **kwargs)\n",
      " |      Initialize self.  See help(type(self)) for accurate signature.\n",
      " |  \n",
      " |  __iter__(self, /)\n",
      " |      Implement iter(self).\n",
      " |  \n",
      " |  __le__(self, value, /)\n",
      " |      Return self<=value.\n",
      " |  \n",
      " |  __len__(self, /)\n",
      " |      Return len(self).\n",
      " |  \n",
      " |  __lt__(self, value, /)\n",
      " |      Return self<value.\n",
      " |  \n",
      " |  __ne__(self, value, /)\n",
      " |      Return self!=value.\n",
      " |  \n",
      " |  __repr__(self, /)\n",
      " |      Return repr(self).\n",
      " |  \n",
      " |  __reversed__(self, /)\n",
      " |      Return a reverse iterator over the dict keys.\n",
      " |  \n",
      " |  __setitem__(self, key, value, /)\n",
      " |      Set self[key] to value.\n",
      " |  \n",
      " |  __sizeof__(...)\n",
      " |      D.__sizeof__() -> size of D in memory, in bytes\n",
      " |  \n",
      " |  clear(...)\n",
      " |      D.clear() -> None.  Remove all items from D.\n",
      " |  \n",
      " |  copy(...)\n",
      " |      D.copy() -> a shallow copy of D\n",
      " |  \n",
      " |  get(self, key, default=None, /)\n",
      " |      Return the value for key if key is in the dictionary, else default.\n",
      " |  \n",
      " |  items(...)\n",
      " |      D.items() -> a set-like object providing a view on D's items\n",
      " |  \n",
      " |  keys(...)\n",
      " |      D.keys() -> a set-like object providing a view on D's keys\n",
      " |  \n",
      " |  pop(...)\n",
      " |      D.pop(k[,d]) -> v, remove specified key and return the corresponding value.\n",
      " |      If key is not found, d is returned if given, otherwise KeyError is raised\n",
      " |  \n",
      " |  popitem(self, /)\n",
      " |      Remove and return a (key, value) pair as a 2-tuple.\n",
      " |      \n",
      " |      Pairs are returned in LIFO (last-in, first-out) order.\n",
      " |      Raises KeyError if the dict is empty.\n",
      " |  \n",
      " |  setdefault(self, key, default=None, /)\n",
      " |      Insert key with a value of default if key is not in the dictionary.\n",
      " |      \n",
      " |      Return the value for key if key is in the dictionary, else default.\n",
      " |  \n",
      " |  update(...)\n",
      " |      D.update([E, ]**F) -> None.  Update D from dict/iterable E and F.\n",
      " |      If E is present and has a .keys() method, then does:  for k in E: D[k] = E[k]\n",
      " |      If E is present and lacks a .keys() method, then does:  for k, v in E: D[k] = v\n",
      " |      In either case, this is followed by: for k in F:  D[k] = F[k]\n",
      " |  \n",
      " |  values(...)\n",
      " |      D.values() -> an object providing a view on D's values\n",
      " |  \n",
      " |  ----------------------------------------------------------------------\n",
      " |  Class methods defined here:\n",
      " |  \n",
      " |  fromkeys(iterable, value=None, /) from builtins.type\n",
      " |      Create a new dictionary with keys from iterable and values set to value.\n",
      " |  \n",
      " |  ----------------------------------------------------------------------\n",
      " |  Static methods defined here:\n",
      " |  \n",
      " |  __new__(*args, **kwargs) from builtins.type\n",
      " |      Create and return a new object.  See help(type) for accurate signature.\n",
      " |  \n",
      " |  ----------------------------------------------------------------------\n",
      " |  Data and other attributes defined here:\n",
      " |  \n",
      " |  __hash__ = None\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(dict)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "42af1bf8",
   "metadata": {},
   "source": [
    "### 1.setdefault 有则不变，无则增加\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "cf0ea307",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'luolinsheng'"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stud_info.setdefault(\"stud_2101\",\"luolinsheng\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "78e2660e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'stud_2101': 'luolinsheng', 'stud_2103': 'xiaojun'}\n"
     ]
    }
   ],
   "source": [
    "print(stud_info)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "23e33524",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'gugu'"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stud_info.setdefault(\"stud_2104\",\"gugu\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "98a7f968",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'stud_2101': 'luolinsheng', 'stud_2103': 'xiaojun', 'stud_2104': 'gugu'}\n"
     ]
    }
   ],
   "source": [
    "print(stud_info)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "82d9f3b6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function setdefault:\n",
      "\n",
      "setdefault(key, default=None, /) method of builtins.dict instance\n",
      "    Insert key with a value of default if key is not in the dictionary.\n",
      "    \n",
      "    Return the value for key if key is in the dictionary, else default.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(stud_info.setdefault)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4d69e2d2",
   "metadata": {},
   "source": [
    "### 2.pop  (1).按照键删除键值对，有返回值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "fc448c2c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'stud_2101': 'luolinsheng', 'stud_2103': 'xiaojun', 'stud_2104': 'gugu'}"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stud_info"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "aa440ce1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "luolinsheng\n"
     ]
    }
   ],
   "source": [
    "b=stud_info.pop('stud_2101')\n",
    "print(b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "fe6368fe",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'stud_2103': 'xiaojun', 'stud_2104': 'gugu'}"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stud_info"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "33bb9f3c",
   "metadata": {},
   "source": [
    "### (2).如果设置了第二个参数则无论字典中有无此键都不会报错"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "c465cfae",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'stud_2101': 'luolinsheng', 'stud_2102': 'beibei', 'stud_2103': 'xiaojun'}\n"
     ]
    }
   ],
   "source": [
    "stud_info={\n",
    "    \"stud_2101\":\"luolinsheng\",\n",
    "    \"stud_2102\":\"beibei\",\n",
    "    \"stud_2103\":\"xiaojun\"\n",
    "}\n",
    "print(stud_info)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "c56bfdc7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "good\n"
     ]
    }
   ],
   "source": [
    "b=stud_info.pop(\"sex\",\"good\")\n",
    "print(b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "3573971f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'stud_2101': 'luolinsheng', 'stud_2102': 'beibei', 'stud_2103': 'xiaojun'}\n"
     ]
    }
   ],
   "source": [
    "print(stud_info)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "6cc9fcf6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function pop:\n",
      "\n",
      "pop(...) method of builtins.dict instance\n",
      "    D.pop(k[,d]) -> v, remove specified key and return the corresponding value.\n",
      "    If key is not found, d is returned if given, otherwise KeyError is raised\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(stud_info.pop)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d9cfbd7c",
   "metadata": {},
   "source": [
    "### 3.clear 清空"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "e320db71",
   "metadata": {},
   "outputs": [],
   "source": [
    "stud_info.clear()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "id": "571d1d3c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{}\n"
     ]
    }
   ],
   "source": [
    "print(stud_info)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "id": "e83d59e7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on NoneType object:\n",
      "\n",
      "class NoneType(object)\n",
      " |  Methods defined here:\n",
      " |  \n",
      " |  __bool__(self, /)\n",
      " |      self != 0\n",
      " |  \n",
      " |  __repr__(self, /)\n",
      " |      Return repr(self).\n",
      " |  \n",
      " |  ----------------------------------------------------------------------\n",
      " |  Static methods defined here:\n",
      " |  \n",
      " |  __new__(*args, **kwargs) from builtins.type\n",
      " |      Create and return a new object.  See help(type) for accurate signature.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(stud_info.clear())"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "917bb6cc",
   "metadata": {},
   "source": [
    "###  4.get的使用"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "id": "640c63ae",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'stud_2101': 'luolinsheng', 'stud_2102': 'beibei', 'stud_2103': 'xiaojun'}\n"
     ]
    }
   ],
   "source": [
    "stud_info={\n",
    "    \"stud_2101\":\"luolinsheng\",\n",
    "    \"stud_2102\":\"beibei\",\n",
    "    \"stud_2103\":\"xiaojun\"\n",
    "}\n",
    "print(stud_info)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "id": "af34fc70",
   "metadata": {},
   "outputs": [],
   "source": [
    "a=stud_info.get( 'stud_2102')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "id": "04fee1c7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "beibei\n"
     ]
    }
   ],
   "source": [
    "print(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "id": "93409333",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'stud_2101': 'luolinsheng', 'stud_2102': 'beibei', 'stud_2103': 'xiaojun'}\n"
     ]
    }
   ],
   "source": [
    "print(stud_info)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "id": "227350b5",
   "metadata": {},
   "outputs": [],
   "source": [
    "b=stud_info.get( 'stud_2109')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "id": "426d3844",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "None\n"
     ]
    }
   ],
   "source": [
    "print(b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "id": "e1131f6f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'stud_2101': 'luolinsheng', 'stud_2102': 'beibei', 'stud_2103': 'xiaojun'}\n"
     ]
    }
   ],
   "source": [
    "print(stud_info)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "id": "32e22a12",
   "metadata": {},
   "outputs": [],
   "source": [
    "c=stud_info.get( 'stud_2109','wawa')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "id": "e2a2251b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "wawa\n"
     ]
    }
   ],
   "source": [
    "print(c)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "id": "86b2cba9",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'stud_2101': 'luolinsheng', 'stud_2102': 'beibei', 'stud_2103': 'xiaojun'}\n"
     ]
    }
   ],
   "source": [
    "print(stud_info)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "id": "cfd7cc64",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function get:\n",
      "\n",
      "get(key, default=None, /) method of builtins.dict instance\n",
      "    Return the value for key if key is in the dictionary, else default.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(stud_info.get)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "691a5b63",
   "metadata": {},
   "source": [
    "### 5.keys()使用"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "id": "f842c777",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'stud_2101': 'luolinsheng', 'stud_2102': 'beibei', 'stud_2103': 'xiaojun'}\n"
     ]
    }
   ],
   "source": [
    "stud_info={\n",
    "    \"stud_2101\":\"luolinsheng\",\n",
    "    \"stud_2102\":\"beibei\",\n",
    "    \"stud_2103\":\"xiaojun\"\n",
    "}\n",
    "print(stud_info)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "id": "98e1c1dd",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "dict_keys(['stud_2101', 'stud_2102', 'stud_2103'])\n",
      "<class 'dict_keys'>\n"
     ]
    }
   ],
   "source": [
    "# 1.特殊的数据类型，类似于列表，但没有索引值\n",
    "print(stud_info.keys())\n",
    "print(type(stud_info.keys()))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "id": "c026dac6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['stud_2101', 'stud_2102', 'stud_2103']\n"
     ]
    }
   ],
   "source": [
    "# 2.可以转化为列表\n",
    "a=list(stud_info.keys())\n",
    "print(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "id": "24bcce2e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "stud_2101,stud_2102,stud_2103,"
     ]
    }
   ],
   "source": [
    "# 3.循环遍历\n",
    "for k in stud_info.keys():\n",
    "    print(k,end=',')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "id": "d9a4981b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "stud_2101,stud_2102,stud_2103,"
     ]
    }
   ],
   "source": [
    "for k in stud_info:\n",
    "    print(k,end=',')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "id": "211b1799",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on dict_keys object:\n",
      "\n",
      "class dict_keys(object)\n",
      " |  Built-in subclasses:\n",
      " |      odict_keys\n",
      " |  \n",
      " |  Methods defined here:\n",
      " |  \n",
      " |  __and__(self, value, /)\n",
      " |      Return self&value.\n",
      " |  \n",
      " |  __contains__(self, key, /)\n",
      " |      Return key in self.\n",
      " |  \n",
      " |  __eq__(self, value, /)\n",
      " |      Return self==value.\n",
      " |  \n",
      " |  __ge__(self, value, /)\n",
      " |      Return self>=value.\n",
      " |  \n",
      " |  __getattribute__(self, name, /)\n",
      " |      Return getattr(self, name).\n",
      " |  \n",
      " |  __gt__(self, value, /)\n",
      " |      Return self>value.\n",
      " |  \n",
      " |  __iter__(self, /)\n",
      " |      Implement iter(self).\n",
      " |  \n",
      " |  __le__(self, value, /)\n",
      " |      Return self<=value.\n",
      " |  \n",
      " |  __len__(self, /)\n",
      " |      Return len(self).\n",
      " |  \n",
      " |  __lt__(self, value, /)\n",
      " |      Return self<value.\n",
      " |  \n",
      " |  __ne__(self, value, /)\n",
      " |      Return self!=value.\n",
      " |  \n",
      " |  __or__(self, value, /)\n",
      " |      Return self|value.\n",
      " |  \n",
      " |  __rand__(self, value, /)\n",
      " |      Return value&self.\n",
      " |  \n",
      " |  __repr__(self, /)\n",
      " |      Return repr(self).\n",
      " |  \n",
      " |  __reversed__(...)\n",
      " |      Return a reverse iterator over the dict keys.\n",
      " |  \n",
      " |  __ror__(self, value, /)\n",
      " |      Return value|self.\n",
      " |  \n",
      " |  __rsub__(self, value, /)\n",
      " |      Return value-self.\n",
      " |  \n",
      " |  __rxor__(self, value, /)\n",
      " |      Return value^self.\n",
      " |  \n",
      " |  __sub__(self, value, /)\n",
      " |      Return self-value.\n",
      " |  \n",
      " |  __xor__(self, value, /)\n",
      " |      Return self^value.\n",
      " |  \n",
      " |  isdisjoint(...)\n",
      " |      Return True if the view and the given iterable have a null intersection.\n",
      " |  \n",
      " |  ----------------------------------------------------------------------\n",
      " |  Data and other attributes defined here:\n",
      " |  \n",
      " |  __hash__ = None\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(stud_info.keys())"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6f451be4",
   "metadata": {},
   "source": [
    "###  6.values()使用"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "id": "95038e56",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "dict_values(['luolinsheng', 'beibei', 'xiaojun'])\n"
     ]
    }
   ],
   "source": [
    "# 1.特殊的数据类型，类似于列表，但没有索引值\n",
    "print(stud_info.values())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "id": "677408df",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['luolinsheng', 'beibei', 'xiaojun']\n"
     ]
    }
   ],
   "source": [
    "# 2.可以转化为列表\n",
    "print(list(stud_info.values()))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "id": "88321cfa",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "luolinsheng,beibei,xiaojun,"
     ]
    }
   ],
   "source": [
    "# 3.循环遍历\n",
    "for val in stud_info.values():\n",
    "    print(val,end=',')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "id": "d8234772",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on dict_values object:\n",
      "\n",
      "class dict_values(object)\n",
      " |  Built-in subclasses:\n",
      " |      odict_values\n",
      " |  \n",
      " |  Methods defined here:\n",
      " |  \n",
      " |  __getattribute__(self, name, /)\n",
      " |      Return getattr(self, name).\n",
      " |  \n",
      " |  __iter__(self, /)\n",
      " |      Implement iter(self).\n",
      " |  \n",
      " |  __len__(self, /)\n",
      " |      Return len(self).\n",
      " |  \n",
      " |  __repr__(self, /)\n",
      " |      Return repr(self).\n",
      " |  \n",
      " |  __reversed__(...)\n",
      " |      Return a reverse iterator over the dict values.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(stud_info.values())"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c233ec7d",
   "metadata": {},
   "source": [
    "### 7.items()使用"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "id": "75a0dd62",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "dict_items([('stud_2101', 'luolinsheng'), ('stud_2102', 'beibei'), ('stud_2103', 'xiaojun')])\n"
     ]
    }
   ],
   "source": [
    "print(stud_info.items())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "id": "99cecf6a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "('stud_2101', 'luolinsheng')\n",
      "('stud_2102', 'beibei')\n",
      "('stud_2103', 'xiaojun')\n"
     ]
    }
   ],
   "source": [
    "for it in stud_info.items():\n",
    "    print(it)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "id": "f6e9e546",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "stud_2101 luolinsheng\n",
      "stud_2102 beibei\n",
      "stud_2103 xiaojun\n"
     ]
    }
   ],
   "source": [
    "# 利用了元组的拆包\n",
    "for key,value in stud_info.items():\n",
    "    print(key,value)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c4a7916d",
   "metadata": {},
   "source": [
    "### 8.copy使用"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "id": "b1e1dc9d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'one': 1, 'two': 2, 'three': 3}\n"
     ]
    }
   ],
   "source": [
    "# 浅copy\n",
    "a=dict(one=1,two=2,three=3)\n",
    "b=a.copy()\n",
    "print(b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "id": "52918763",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on dict object:\n",
      "\n",
      "class dict(object)\n",
      " |  dict() -> new empty dictionary\n",
      " |  dict(mapping) -> new dictionary initialized from a mapping object's\n",
      " |      (key, value) pairs\n",
      " |  dict(iterable) -> new dictionary initialized as if via:\n",
      " |      d = {}\n",
      " |      for k, v in iterable:\n",
      " |          d[k] = v\n",
      " |  dict(**kwargs) -> new dictionary initialized with the name=value pairs\n",
      " |      in the keyword argument list.  For example:  dict(one=1, two=2)\n",
      " |  \n",
      " |  Built-in subclasses:\n",
      " |      StgDict\n",
      " |  \n",
      " |  Methods defined here:\n",
      " |  \n",
      " |  __contains__(self, key, /)\n",
      " |      True if the dictionary has the specified key, else False.\n",
      " |  \n",
      " |  __delitem__(self, key, /)\n",
      " |      Delete self[key].\n",
      " |  \n",
      " |  __eq__(self, value, /)\n",
      " |      Return self==value.\n",
      " |  \n",
      " |  __ge__(self, value, /)\n",
      " |      Return self>=value.\n",
      " |  \n",
      " |  __getattribute__(self, name, /)\n",
      " |      Return getattr(self, name).\n",
      " |  \n",
      " |  __getitem__(...)\n",
      " |      x.__getitem__(y) <==> x[y]\n",
      " |  \n",
      " |  __gt__(self, value, /)\n",
      " |      Return self>value.\n",
      " |  \n",
      " |  __init__(self, /, *args, **kwargs)\n",
      " |      Initialize self.  See help(type(self)) for accurate signature.\n",
      " |  \n",
      " |  __iter__(self, /)\n",
      " |      Implement iter(self).\n",
      " |  \n",
      " |  __le__(self, value, /)\n",
      " |      Return self<=value.\n",
      " |  \n",
      " |  __len__(self, /)\n",
      " |      Return len(self).\n",
      " |  \n",
      " |  __lt__(self, value, /)\n",
      " |      Return self<value.\n",
      " |  \n",
      " |  __ne__(self, value, /)\n",
      " |      Return self!=value.\n",
      " |  \n",
      " |  __repr__(self, /)\n",
      " |      Return repr(self).\n",
      " |  \n",
      " |  __reversed__(self, /)\n",
      " |      Return a reverse iterator over the dict keys.\n",
      " |  \n",
      " |  __setitem__(self, key, value, /)\n",
      " |      Set self[key] to value.\n",
      " |  \n",
      " |  __sizeof__(...)\n",
      " |      D.__sizeof__() -> size of D in memory, in bytes\n",
      " |  \n",
      " |  clear(...)\n",
      " |      D.clear() -> None.  Remove all items from D.\n",
      " |  \n",
      " |  copy(...)\n",
      " |      D.copy() -> a shallow copy of D\n",
      " |  \n",
      " |  get(self, key, default=None, /)\n",
      " |      Return the value for key if key is in the dictionary, else default.\n",
      " |  \n",
      " |  items(...)\n",
      " |      D.items() -> a set-like object providing a view on D's items\n",
      " |  \n",
      " |  keys(...)\n",
      " |      D.keys() -> a set-like object providing a view on D's keys\n",
      " |  \n",
      " |  pop(...)\n",
      " |      D.pop(k[,d]) -> v, remove specified key and return the corresponding value.\n",
      " |      If key is not found, d is returned if given, otherwise KeyError is raised\n",
      " |  \n",
      " |  popitem(self, /)\n",
      " |      Remove and return a (key, value) pair as a 2-tuple.\n",
      " |      \n",
      " |      Pairs are returned in LIFO (last-in, first-out) order.\n",
      " |      Raises KeyError if the dict is empty.\n",
      " |  \n",
      " |  setdefault(self, key, default=None, /)\n",
      " |      Insert key with a value of default if key is not in the dictionary.\n",
      " |      \n",
      " |      Return the value for key if key is in the dictionary, else default.\n",
      " |  \n",
      " |  update(...)\n",
      " |      D.update([E, ]**F) -> None.  Update D from dict/iterable E and F.\n",
      " |      If E is present and has a .keys() method, then does:  for k in E: D[k] = E[k]\n",
      " |      If E is present and lacks a .keys() method, then does:  for k, v in E: D[k] = v\n",
      " |      In either case, this is followed by: for k in F:  D[k] = F[k]\n",
      " |  \n",
      " |  values(...)\n",
      " |      D.values() -> an object providing a view on D's values\n",
      " |  \n",
      " |  ----------------------------------------------------------------------\n",
      " |  Class methods defined here:\n",
      " |  \n",
      " |  fromkeys(iterable, value=None, /) from builtins.type\n",
      " |      Create a new dictionary with keys from iterable and values set to value.\n",
      " |  \n",
      " |  ----------------------------------------------------------------------\n",
      " |  Static methods defined here:\n",
      " |  \n",
      " |  __new__(*args, **kwargs) from builtins.type\n",
      " |      Create and return a new object.  See help(type) for accurate signature.\n",
      " |  \n",
      " |  ----------------------------------------------------------------------\n",
      " |  Data and other attributes defined here:\n",
      " |  \n",
      " |  __hash__ = None\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(stud_info.copy())"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2834559d",
   "metadata": {},
   "source": [
    "###  9.popitem()使用"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "id": "a9c4a4f1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'one': 1, 'two': 2, 'three': 3, 'four': 4}\n",
      "('five', 5)\n"
     ]
    }
   ],
   "source": [
    "# 随机删除字典中的一对  键和值\n",
    "a=dict(one=1,two=2,three=3,four=4,five=5)\n",
    "b=a.popitem()\n",
    "print(a)\n",
    "print(b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 82,
   "id": "9225e7a9",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on tuple object:\n",
      "\n",
      "class tuple(object)\n",
      " |  tuple(iterable=(), /)\n",
      " |  \n",
      " |  Built-in immutable sequence.\n",
      " |  \n",
      " |  If no argument is given, the constructor returns an empty tuple.\n",
      " |  If iterable is specified the tuple is initialized from iterable's items.\n",
      " |  \n",
      " |  If the argument is a tuple, the return value is the same object.\n",
      " |  \n",
      " |  Built-in subclasses:\n",
      " |      asyncgen_hooks\n",
      " |      UnraisableHookArgs\n",
      " |  \n",
      " |  Methods defined here:\n",
      " |  \n",
      " |  __add__(self, value, /)\n",
      " |      Return self+value.\n",
      " |  \n",
      " |  __contains__(self, key, /)\n",
      " |      Return key in self.\n",
      " |  \n",
      " |  __eq__(self, value, /)\n",
      " |      Return self==value.\n",
      " |  \n",
      " |  __ge__(self, value, /)\n",
      " |      Return self>=value.\n",
      " |  \n",
      " |  __getattribute__(self, name, /)\n",
      " |      Return getattr(self, name).\n",
      " |  \n",
      " |  __getitem__(self, key, /)\n",
      " |      Return self[key].\n",
      " |  \n",
      " |  __getnewargs__(self, /)\n",
      " |  \n",
      " |  __gt__(self, value, /)\n",
      " |      Return self>value.\n",
      " |  \n",
      " |  __hash__(self, /)\n",
      " |      Return hash(self).\n",
      " |  \n",
      " |  __iter__(self, /)\n",
      " |      Implement iter(self).\n",
      " |  \n",
      " |  __le__(self, value, /)\n",
      " |      Return self<=value.\n",
      " |  \n",
      " |  __len__(self, /)\n",
      " |      Return len(self).\n",
      " |  \n",
      " |  __lt__(self, value, /)\n",
      " |      Return self<value.\n",
      " |  \n",
      " |  __mul__(self, value, /)\n",
      " |      Return self*value.\n",
      " |  \n",
      " |  __ne__(self, value, /)\n",
      " |      Return self!=value.\n",
      " |  \n",
      " |  __repr__(self, /)\n",
      " |      Return repr(self).\n",
      " |  \n",
      " |  __rmul__(self, value, /)\n",
      " |      Return value*self.\n",
      " |  \n",
      " |  count(self, value, /)\n",
      " |      Return number of occurrences of value.\n",
      " |  \n",
      " |  index(self, value, start=0, stop=9223372036854775807, /)\n",
      " |      Return first index of value.\n",
      " |      \n",
      " |      Raises ValueError if the value is not present.\n",
      " |  \n",
      " |  ----------------------------------------------------------------------\n",
      " |  Static methods defined here:\n",
      " |  \n",
      " |  __new__(*args, **kwargs) from builtins.type\n",
      " |      Create and return a new object.  See help(type) for accurate signature.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(a.popitem())"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b77de4f1",
   "metadata": {},
   "source": [
    "### 10.fromkeys()使用"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 83,
   "id": "2355be75",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'k1': None, 'k2': None, 'k3': None}\n"
     ]
    }
   ],
   "source": [
    "# 没有指定value，默认none\n",
    "a=stud_info.fromkeys(['k1','k2','k3'])\n",
    "print(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 84,
   "id": "26c4f738",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'k1': 'value', 'k2': 'value', 'k3': 'value'}\n"
     ]
    }
   ],
   "source": [
    "# 指定value\n",
    "a=stud_info.fromkeys(['k1','k2','k3'],'value')\n",
    "print(a)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cbfa6ca2",
   "metadata": {},
   "source": [
    "###  11.update()使用 \n",
    "#####   (更新，有则覆盖，无则添加)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 90,
   "id": "6910cb02",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'stud_2101': 'luolinsheng', 'stud_2102': 'beibei', 'stud_2103': 'xiaojun', 'stud_2104': 'ziqi', 'stud_2105': 'gugu'}\n"
     ]
    }
   ],
   "source": [
    "# 1.增加键值对\n",
    "# 方式一：\n",
    "stud_info={\n",
    "    \"stud_2101\":\"luolinsheng\",\n",
    "    \"stud_2102\":\"beibei\",\n",
    "    \"stud_2103\":\"xiaojun\"\n",
    "}\n",
    "stud_info.update(stud_2104='ziqi',stud_2105='gugu')\n",
    "print(stud_info)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 95,
   "id": "b01a308f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'stud_2101': 'luolinsheng', 'stud_2102': 'beibei', 'stud_2103': 'xiaojun', 'stud_2104': 'ziqi', 'stud_2105': 'gugu'}\n"
     ]
    }
   ],
   "source": [
    "# 方式二：\n",
    "stud_info={\n",
    "    \"stud_2101\":\"luolinsheng\",\n",
    "    \"stud_2102\":\"beibei\",\n",
    "    \"stud_2103\":\"xiaojun\"\n",
    "}\n",
    "stud_info.update([('stud_2104','ziqi'),('stud_2105','gugu')])\n",
    "print(stud_info)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 96,
   "id": "0084d058",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'stud_2101': 'luolinsheng', 'stud_2102': 'beibei', 'stud_2103': 'xiaojun', 'stud_2104': 'gugu'}\n"
     ]
    }
   ],
   "source": [
    "# 方式三\n",
    "stud_info={\n",
    "    \"stud_2101\":\"luolinsheng\",\n",
    "    \"stud_2102\":\"beibei\",\n",
    "    \"stud_2103\":\"xiaojun\"\n",
    "}\n",
    "b={\n",
    "   'stud_2104': 'gugu'\n",
    "}\n",
    "stud_info.update(b)\n",
    "print(stud_info)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 98,
   "id": "175d9621",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'stud_2101': 'luolinsheng', 'stud_2102': 'beibei', 'stud_2103': 'tom'}\n"
     ]
    }
   ],
   "source": [
    "# 2.修改键所对应的值\n",
    "stud_info={\n",
    "    \"stud_2101\":\"luolinsheng\",\n",
    "    \"stud_2102\":\"beibei\",\n",
    "    \"stud_2103\":\"xiaojun\"\n",
    "}\n",
    "stud_info.update(stud_2103='tom')\n",
    "print(stud_info)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 99,
   "id": "ea5400f3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function update:\n",
      "\n",
      "update(...) method of builtins.dict instance\n",
      "    D.update([E, ]**F) -> None.  Update D from dict/iterable E and F.\n",
      "    If E is present and has a .keys() method, then does:  for k in E: D[k] = E[k]\n",
      "    If E is present and lacks a .keys() method, then does:  for k, v in E: D[k] = v\n",
      "    In either case, this is followed by: for k in F:  D[k] = F[k]\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(stud_info.update)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "83c51426",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
